/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：RestRequestCallBack.java <br>
 * 创建时间：2015年4月28日 下午5:34:34 <br>
 * 所属项目：GmudEX <br>
 * @author 12548
 */
package lostland.general.network;

import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;

import lostland.gmud.exv2.ui.LockedScreen;

/**
 * 类名：RestRequestCallBack <br>
 * 说明：
 *
 * @author 12548
 */
public class GmudRequestCallBack extends RequestCallBack<String> {

	private int lockID;

	/**
	 * @return lockID
	 */
	public int getLockID() {
		return lockID;
	}

	/**
	 * @param lockID 要设置的 lockID
	 */
	public void setLockID(int lockID) {
		this.lockID = lockID;
	}

	private GmudRequestListener listener = null;

	/**
	 *
	 */
	public GmudRequestCallBack(int lockID) {
		super();
		this.lockID = lockID;
	}

	protected void setListener(GmudRequestListener listener) {
		this.listener = listener;
	}


	/* （非 Javadoc）
	 * @see com.lidroid.xutils.http.callback.RequestCallBack#onCancelled()
	 */
	@Override
	public void onCancelled() {
		LockedScreen.unLock(lockID);
		super.onCancelled();
	}


	/* （非 Javadoc）
	 * @see com.lidroid.xutils.http.callback.RequestCallBack#onStart()
	 */
	@Override
	public void onStart() {
		super.onStart();
	}


	/* （非 Javadoc）
	 * @see com.lidroid.xutils.http.callback.RequestCallBack#onFailure(com.lidroid.xutils.exception.HttpException, java.lang.String)
	 */
	@Override
	public void onFailure(HttpException arg0, String arg1) {
		LockedScreen.unLock(lockID);
		if (listener != null) {
			listener.onFail(arg0, arg1);
		}
	}

	/* （非 Javadoc）
	 * @see com.lidroid.xutils.http.callback.RequestCallBack#onSuccess(com.lidroid.xutils.http.ResponseInfo)
	 */
	@Override
	public void onSuccess(ResponseInfo<String> arg0) {
		LockedScreen.unLock(lockID);
		if (listener != null) {
			if (arg0.statusCode == 200) {
				listener.onSucc(arg0);
			} else {
				listener.onFail(new HttpException(), "其他错误！");
			}
		}
	}

}
